# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=tiny-dnn
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.0.0a3
pkgrel=6
pkgdesc="C++14 implementation of deep learning (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
license=('spdx:BSD-3-Clause')
#depends=("${MINGW_PACKAGE_PREFIX}-tbb")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-protobuf")
url="https://tiny-dnn.readthedocs.io/"
source=(${_realname}-${pkgver}.tar.gz::https://github.com/tiny-dnn/tiny-dnn/archive/v${pkgver}.tar.gz
        0001-build-fixes.patch
        0002-googletest-src.patch)
options=('!strip' 'staticlibs')
sha256sums=('e2c61ce8c5debaa644121179e9dbdcf83f497f39de853f8dd5175846505aa18b'
            '4b0660757ca19127dff48796d15e2c072ea03417700fbf7a43babd71ef6e6602'
            '63088bce9e37bf3d814340fc71ea186f5656ec801268ae09a895c4275bc687ac')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/0001-build-fixes.patch
  patch -p1 -i ${srcdir}/0002-googletest-src.patch
}

build() {
  [[ -d ${srcdir}/build-${MSYSTEM} ]] && rm -rf ${srcdir}/build-${MSYSTEM}
  mkdir -p ${srcdir}/build-${MSYSTEM} && cd ${srcdir}/build-${MSYSTEM}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"Ninja" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Release \
    -DUSE_TBB=OFF \
    $([[ ${MSYSTEM_CARCH} == aarch64 ]] && echo "-DUSE_SSE=OFF") \
    $([[ ${MSYSTEM_CARCH} == aarch64 ]] && echo "-DUSE_AVX=OFF") \
    -DBUILD_TESTS=ON \
    -DINSTALL_GTEST=OFF \
    ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/cmake --build . --target generated_proto
}

check() {
  cd ${srcdir}/${_realname}-${pkgver}/test
  ${srcdir}/build-${MINGW_CHOST}/test/tiny_dnn_test.exe || true
}

package() {
  cd "${srcdir}//build-${MSYSTEM}"
  DESTDIR=${pkgdir} ${MINGW_PREFIX}/bin/cmake --install .
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
